﻿using System;
using System.Collections.Generic;
using BattleCity.Classes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace BattleCity.GameObjects
{
    public class Base : gBaseClass
    {
        Animation _idle;
        Animation _die;
        SoundEffect _dieSound;
        bool _flag;

        public event EventHandler GameOver;

        public Base(BattleCityGame game, ref AnimationPlayer spr, Vector2 sprPosition, List<Animation> animList, SoundEffect sound)
            : base(game, ref spr, sprPosition, game.SpriteRec16, 0.9f)
        {
            IsAlive = true;
            _idle = animList[0];
            _die = animList[1];
            _dieSound = sound;
            _sprite.PlayAnimation(_idle);
        }
        public override void Initialize()
        {
            base.Initialize();
        }
        public override void Update(GameTime gameTime)
        {
            if (!IsAlive && !_flag)
            {
                _flag = true;
                _dieSound.Play();
                this.SprPosition.X -= 16f;
                this.SprPosition.Y -= 16f;
                _sprite.PlayAnimation(_die);
                if (GameOver != null)
                    GameOver(this, new EventArgs());
            }
            base.Update(gameTime);
        }
    }
}